#ifndef _PID_H
#define _PID_H

#include "encoder.h"
#include "timer.h"
#include "sys.h"

struct PID {
    //目标值
    int16_t target;
    //PID系数
    float Kp, Ki, Kd;
    //误差值
    float err_last, integral;
    //限幅
    int max_output, max_integral;
    //输出
    int output;

    int speed;
};

extern struct PID pid;

void pid_init(struct PID *pid);

void pid_reset(struct PID *pid);

int pid_count(struct PID *pid);

void set_motor(int output);

#endif
